package com.myapp.api.mapper;

import com.myapp.api.entity.Teacher;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface TeacherMapper {
    @Delete({
        "delete from teacher",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into teacher (id, Tid, ",
        "Tname, Sex, Pwd, ",
        "Job, Phone, Count, ",
        "LoginTime, LoginIp, ",
            "Role, CreateTime, ",
            "UpdateTime, AuthToken)",
            "values (#{id,jdbcType=INTEGER}, #{tid,jdbcType=VARCHAR}, ",
        "#{tname,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, ",
        "#{job,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{count,jdbcType=INTEGER}, ",
        "#{logintime,jdbcType=TIMESTAMP}, #{loginip,jdbcType=VARCHAR}, ",
            "#{role,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, ",
            "#{updatetime,jdbcType=TIMESTAMP}, #{authtoken,jdbcType=LONGVARCHAR})"
    })
    int insert(Teacher record);

    @InsertProvider(type=TeacherSqlProvider.class, method="insertSelective")
    int insertSelective(Teacher record);

    @Select({
        "select",
            "id, Tid, Tname, Sex, Pwd, Job, Phone, Count, LoginTime, LoginIp, Role, CreateTime, ",
            "UpdateTime, AuthToken",
        "from teacher",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
        @Result(column="Tname", property="tname", jdbcType=JdbcType.VARCHAR),
        @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
        @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="Job", property="job", jdbcType=JdbcType.VARCHAR),
        @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
        @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="LoginIp", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Teacher selectByPrimaryKey(Integer id);

    @UpdateProvider(type=TeacherSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Teacher record);

    @Update({
        "update teacher",
            "set Tid = #{tid,jdbcType=VARCHAR},",
            "Tname = #{tname,jdbcType=VARCHAR},",
            "Sex = #{sex,jdbcType=VARCHAR},",
            "Pwd = #{pwd,jdbcType=VARCHAR},",
            "Job = #{job,jdbcType=VARCHAR},",
            "Phone = #{phone,jdbcType=VARCHAR},",
            "Count = #{count,jdbcType=INTEGER},",
            "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
            "LoginIp = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
            "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
            "UpdateTime = #{updatetime,jdbcType=TIMESTAMP},",
            "AuthToken = #{authtoken,jdbcType=LONGVARCHAR}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(Teacher record);

    @Update({
            "update teacher",
            "set Tid = #{tid,jdbcType=VARCHAR},",
            "Tname = #{tname,jdbcType=VARCHAR},",
            "Sex = #{sex,jdbcType=VARCHAR},",
            "Pwd = #{pwd,jdbcType=VARCHAR},",
            "Job = #{job,jdbcType=VARCHAR},",
            "Phone = #{phone,jdbcType=VARCHAR},",
            "Count = #{count,jdbcType=INTEGER},",
            "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
            "LoginIp = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Teacher record);

    @Select({
            "select",
            "id, Tid, Tname, Sex, Pwd, Job, Phone, Count, LoginTime, LoginIp, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from teacher"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Tname", property="tname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Job", property="job", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIp", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Teacher> getTeachers();

    @Select({
            "select",
            "id, Tid, Tname, Sex, Pwd, Job, Phone, Count, LoginTime, LoginIp, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from teacher",
            "where Tid = #{tid,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Tname", property="tname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Job", property="job", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIp", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Teacher getTeacherByTid(String tid);

    @Select({
            "select",
            "id, Tid, Tname, Sex, Pwd, Job, Phone, Count, LoginTime, LoginIp, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from teacher",
            "where Tname like concat('%',#{tname,jdbcType=VARCHAR},'%')"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Tid", property = "tid", jdbcType = JdbcType.VARCHAR),
            @Result(column="Tname", property="tname", jdbcType=JdbcType.VARCHAR),
            @Result(column="Sex", property="sex", jdbcType=JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="Job", property="job", jdbcType=JdbcType.VARCHAR),
            @Result(column="Phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="Count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIp", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Teacher> getTeacherByTname(String tname);

    @Select({
            "select count(*)",
            "id, Tid, Tname, Sex, Pwd, Job, Phone, Count, LoginTime, LoginIp, Role, CreateTime, ",
            "UpdateTime, AuthToken",
            "from teacher",
            "where Tid = #{tid,jdbcType=VARCHAR}"
    })
    Integer getTeacherByOneTid(String tid);
}